﻿/**************************************************************************
创建时间:	2020/5/13 16:41:03    
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com

Copyright (c) zhcun.cn

描	述： 模态窗口
记	录：
***************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ASmile.Win
{
    public partial class FrmBaseModal : FrmBase
    {
        public FrmBaseModal()
        {
            InitializeComponent();
        }

        static readonly Dictionary<Type, Size> LastFormSize = new Dictionary<Type, Size>();

        bool _SizeChanged = false;

        /// <summary>
        /// 是否保持上次更改的窗体大小
        /// </summary>
        [Description("是否保持上次更改的窗体大小")]
        public bool KeepFormSize { set; get; }

        private void FrmBaseModal_Load(object sender, EventArgs e)
        {
            if (KeepFormSize)
            {
                if (LastFormSize.ContainsKey(this.GetType()))
                {
                    this.Size = LastFormSize[GetType()];
                }
                this.SizeChanged += FrmBaseModal_SizeChanged;
                this.FormClosed += FrmBaseModal_FormClosed;                
            }
            BringToFront();
        }

        private void FrmBaseModal_SizeChanged(object sender, EventArgs e)
        {
            _SizeChanged = true;
        }

        private void FrmBaseModal_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (_SizeChanged)
            {
                LastFormSize[this.GetType()] = Size;
            }
        }
    }
}